package com.taihua.cc;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/TestController")
public class TestController {
    //@RequestMapping(value = {"/test","test1"})//用不同的路径：（.../test）或者（.../test1）访问相同的方法 hello
    //访问路径：http://localhost:8080/Third/TestController/test
    @RequestMapping(value = {"test"})//简写：@RequestMapping("/test")
    public String hello(){
        System.out.println("这是控制器的hello方法");
        return "success";//返回一个视图控制器
    }

    @RequestMapping(value = {"/testGet"},method = {RequestMethod.GET,RequestMethod.POST})//@RequestMapping(value = {"testGet"}//到postman里面测试
//    @RequestMapping(value = {"/testGet"},method = RequestMethod.GET)
//    @RequestMapping(value = {"/testGet"})//简写
    public String testGet(){
        System.out.println("这是控制器的testGet方法");
        return "success";
    }
    //@RequestMapping(value = {"/testGet"},method = {RequestMethod.GET})与下面的@GetMapping对等
    @GetMapping("/testGet2")
    public String testGet2(){
        System.out.println("这是控制器的testGet2方法");
        return "success";
    }

    //@RequestMapping(value = {"/testPost"},method = {RequestMethod.Post}
    @PostMapping("/testPost")
    public String testPost(){
        System.out.println("这是控制器的testPost方法");
        return "success";
    }

    //@RequestMapping(value = {"/testPut"},method = {RequestMethod.Put}
    @PutMapping("/testPut")
    public String testPut(){
        System.out.println("这是控制器的testPut方法");
        return "success";
    }

    //@RequestMapping(value = {"/testDelete"},method = {RequestMethod.Delete}
    @DeleteMapping("/testDelete")
    public String testDelete(){
        System.out.println("这是控制器的testDelete方法");
        return "success";
    }


    //获取参数的三种方法(Param,Ant,RESTful)
    @RequestMapping(value = {"/testParam"},method = {RequestMethod.GET,RequestMethod.POST},params = "id=2")//http://localhost:8080/Third/TestController/testParam?id=2
    public String testParam(){
        System.out.println("testParam");
        return "success";
    }

    @RequestMapping(value = {"/testAnt"},method = {RequestMethod.GET,RequestMethod.POST})//http://localhost:8080/Third/TestController/testparam?name=abc&password=123456
    public String testAnt(){
        System.out.println("testAnt");
        return "success";
    }

    @RequestMapping(value = {"/testRESTful"},method = {RequestMethod.GET,RequestMethod.POST})//http://localhost:8080/Third/TestController/testparam/name/abc
    public String testRESTful(){
        System.out.println("这是控制器的testDelete方法");
        return "success";
    }
}
